#include "atm.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using std::ifstream;
using std::ofstream;
using std::string;
using std::istringstream;

bool Atm::loadUsers(const char* userFile) {
	ifstream in(userFile);
	if(!in) return false;
	string line;
	string id, password;
	double money;
	while(getline(in, line)){
		istringstream is(line);
		is >> id >> password >> money;
		users.push_back(User(id, password, money));
	}
	in.close();
	return true;
}
bool Atm::writeUsers(const char* userFile){
	ofstream out(userFile);
	if(!out) return false;
	vector<User>::iterator iter = users.begin();
	for (; iter != users.end(); ++iter)
		out << iter->getId() <<  " "  
			<< iter->getPassword() << " " 
			<<  iter->money() << std::endl;
	out.close();
	return true;
}
